import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        theme: ThemeData(
          useMaterial3: false,
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: const Text("Flutter App"),
          ),
          body: const MyHome(),
        ));
  }
}

class MyHome extends StatefulWidget {
  const MyHome({super.key});

  @override
  State<MyHome> createState() => _MyHomeState();
}

class _MyHomeState extends State<MyHome> {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: [
        SliverGrid(
            delegate: SliverChildBuilderDelegate(
              (BuildContext context,int index){
                return Container(
                  color: Colors.blue[100 * (index % 9 + 1)],
                  alignment: Alignment.center,
                  child: Text('Grid $index'),
                );
              },
              childCount: 50,
            ),
            // 指定每行3个元素，类似GridView
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3)
        )
      ],
    );
  }
}
